package com.whq.thrift.api.web.admin.service.verify.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.verify.MerchantApiPermission;
import com.whq.thrift.api.web.admin.db.verify.MerchantApiPermissionMapper;
import com.whq.thrift.api.web.admin.service.verify.MerchantApiPermissionService;

@Service
public class MerchantApiPermissionServiceImpl implements MerchantApiPermissionService {
	@Autowired
	private MerchantApiPermissionMapper merchantApiPermissionMapper;

	public void addMerchantApiPermission(MerchantApiPermission merchantApiPermission) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (merchantApiPermission == null) {
			return;
		}

		Date date = new Date();
		merchantApiPermission.setCreateTime(date);
		this.merchantApiPermissionMapper.addMerchantApiPermission(merchantApiPermission);
	}
	
	public void delMerchantApiPermission(int id) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		this.merchantApiPermissionMapper.delMerchantApiPermission(id);
	}
	
	public void updMerchantApiPermission(MerchantApiPermission merchantApiPermission) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (merchantApiPermission == null) {
			return;
		}
		Date date = new Date();
		merchantApiPermission.setUpdateTime(date);
		this.merchantApiPermissionMapper.updMerchantApiPermission(merchantApiPermission);
	}

	public List<MerchantApiPermission> getMerchantApiPermissionList(Map<String, Object> map) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");

		return this.merchantApiPermissionMapper.getMerchantApiPermissionList(map);
	}

	public int getMerchantApiPermissionsCount(Map<String, Object> map) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantApiPermissionMapper.getMerchantApiPermissionsCount(map);
	}
	
	public MerchantApiPermission getMerchantApiPermissionById(int id){
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantApiPermissionMapper.getMerchantApiPermissionById(id);
	}

	public MerchantApiPermission getMerchantApiPermissionByName(String merchantName){
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantApiPermissionMapper.getMerchantApiPermissionByName(merchantName);
	}
	
	public MerchantApiPermission getMerchantApiPermissionByApi(String api){
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantApiPermissionMapper.getMerchantApiPermissionByApi(api);
	}
}
